<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Password {
	
	var $CI;
	var $password;
	var $encoded;
	var $key = 'i4@dm!n123$$%';
	
	function __construct($params = array())
	{
		$this->CI =& get_instance();
		
		$this->CI->load->helper('string');
		
		if (count($params) > 0)
		{
		   $this->initialize($params);
		}
	}
	
	/**
	* initialize
	*
	* Set global variables
	*
	* @access public
	* @param void
	* @return void
	*/
	function initialize($params = array())
	{
		if (count($params) > 0)
		{
			foreach ($params as $key => $val)
			{
				if (isset($this->$key))
				{
				   $this->$key = $val;
				}
			}
		}
	}
   
	/**
	 * set_password
	 * 
	 * Set/create password string
	 * 
	 * @access public
	 * @param string
	 * @return string
	 */
	function set_password($password = NULL)
	{
		if (empty($password)) $password = random_string('alnum', 8);
		$this->password = $password;
		
		return $this->password;
	}
	
	/**
	 * get_password
	 * 
	 * Return set password
	 * 
	 * @access public
	 * @param void
	 * @return string
	 */
	function get_password()
	{
		return $this->password;
	}
	
	/**
	 * encode
	 * 
	 * Encrypt password set.
	 * 
	 * @access public
	 * @param void
	 * @return string
	 */
	function encode()
	{
		$this->encoded = sha1($this->password . $this->key);
		return $this->encoded;
	}
}
/* End of file Password.php */
/* Location: ./application/libraries/Password.php */
